package com.ytoglobal.overseas.address.platform.common.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;

/**
 * <pre>
 * 名称: MessageSourceConfiguration
 * 描述: TODO
 * </pre>
 *
 * @author Ryan Chen
 * @since 1.0.0
 */
@Configuration
@ConditionalOnProperty(name = "spring.messages.basename")
public class MessageSourceConfiguration {

    @Value("${spring.messages.basename}")
    private String basename;

    @Bean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename(basename);
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }
}
